# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Brendan MacDonell <macdonellba at gmail dot com>
# Contributor: Linmiao Xu <linmiao.xu@gmail.com>
# Contributor: Juan Miguel Cejuela <juanmi@jmcejuela.net>

pkgname=python-apsw
pkgver=3.43.1.0
pkgrel=1
pkgdesc="Python wrapper for SQLite"
arch=('loong64' 'x86_64')
url="https://github.com/rogerbinns/apsw"
license=('MIT')
makedepends=('python-setuptools')
depends=('python' 'sqlite')
source=("apsw-$pkgver.tar.gz::https://github.com/rogerbinns/apsw/archive/$pkgver.tar.gz")
sha512sums=('a3343af87638f04786086c282cf50bfce3074e2a3165ebf172740be13021138a83356e594969791029879dfef12149775b48e0912eb14817358434b3b72ada67')
b2sums=('3f463896ce587326421ae78a26b5cccbc5c43a2c54b9502c166f599705fc9afe867c3be5f2ea4de8bc4d2da2f3bf09e034a27744d2114a5bc9b5c622bd852543')

build() {
  cd apsw-${pkgver}

  python setup.py build --enable=load_extension
}

check() {
  cd "$srcdir"/apsw-${pkgver}

  gcc ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -fPIC -shared -o testextension.sqlext src/testextension.c
  # do glob expansion in variable assignment
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-${python_version}" python -m unittest discover -vs .
}

package() {
  cd "$srcdir"/apsw-${pkgver}

  python setup.py install --root="$pkgdir" --optimize=1 --skip-build
  install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
